home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / splib43U.lha / superplay-lib_USR / SuperPlay / SuperPlay.c < prev    next >
C/C++ Source or Header  |  1994-12-13  |  16KB  |  570 lines

  1.  
  2.  /* SuperPlay V4.1
  3.     Multi-Sound-Replayer
  4.     (c) 1993-94 by Andreas R. Kleinert. All rights reserved.
  5.     Compiler     : SAS/C V6.51
  6.     Last changes : 02.12.1994
  7.  */
  8.  
  9. #include "SuperPlay.h"
  10. #include <intuition/intuitionbase.h>
  11.  
  12.  
  13.    /* Help-, Info- and Error-Texts */
  14.  
  15. char entry1_text  [] = "\2331;32;40m"SP_STRDEF_VERSION " " SP_STRDEF_DATE"\2330;32;40m\2333;32;40m (SHAREWARE)\2330;32;40m\n(c) 1994 by Andreas Ralph Kleinert. All rights reserved.\n"
  16.                        "Andreas R. Kleinert, Grube Hohe Grethe 23, D-57074 Siegen, Germany.\n";
  17. char entry2_text  [] = "Player program for use with SuperPlay-Library.\n";
  18. char entry3_text  [] = "USAGE : \2330;33;40mSuperPlay\2330;31;40m\n";
  19.  
  20. char ver_text [] = SP_STRDEF_VER SP_STRDEF_VERSION " " SP_STRDEF_DATE;
  21.  
  22. char intuitionlib_text    [] = "You need \42intuition.library\42 V37+ !";
  23. char graphicslib_text    [] = "You need \42graphics.library\42 V37+ !";
  24. char gadtoolslib_text    [] = "You need \42gadtools.library\42 V37+ !";
  25. char asllib_text    [] = "You need \42asl.library\42 V37+ !";
  26. char splib_text      [] = "You need \42superplay.library\42 V3+ !";
  27.  
  28. char no_win_text        [] = "Can't open GUI Window !";
  29. char no_scr_text        [] = "Can't open GUI Screen !";
  30. char no_handle_text     [] = "Not enough memory !";
  31.  
  32.  
  33. /* *************************************************** */
  34. /* *                             * */
  35. /* * Function Declarations                 * */
  36. /* *                             * */
  37. /* *************************************************** */
  38.  
  39. void __regargs SPS_HandleGadgets(void);
  40. void __regargs Leave(char *errtext, APTR mlist, long code);
  41.  
  42. ULONG __regargs SPS_Play(char *filename, ULONG flag);
  43. ULONG __regargs SPS_PlayRequest(ULONG flag);
  44.  
  45. ULONG __regargs SPS_Conv(char *filename, ULONG code);
  46. ULONG __regargs SPS_ConvRequest(ULONG code);
  47.  
  48. ULONG __regargs SPS_FileRequest(struct SP_RememberPath *sprp, char *title, char *left, char *right);
  49. void  __regargs SPS_DisplayError(char *text);
  50.  
  51. void __stdargs SP_Printf(char *formatstring, ...);
  52. void __stdargs SP_SPrintf(char *buffer, char *formatstring, ...);
  53.  
  54.  
  55. /* *************************************************** */
  56. /* *                             * */
  57. /* * Additional Base Declarations             * */
  58. /* *                             * */
  59. /* *************************************************** */
  60.  
  61. struct IntuitionBase *IntuitionBase  = N;
  62. struct GfxBase         *GfxBase         = N;
  63. struct Library         *GadToolsBase   = N;
  64. struct Library         *AslBase        = N;
  65. struct SuperPlayBase *SuperPlayBase  = N;
  66.  
  67.  
  68. /* *************************************************** */
  69. /* *                             * */
  70. /* * Globally Accessed Variables             * */
  71. /* *                             * */
  72. /* *************************************************** */
  73.  
  74. struct SPS_SPOList *SPOList = N;
  75. APTR playhandle             = N;
  76.  
  77.  
  78. /* *************************************************** */
  79. /* *                             * */
  80. /* * Compiler Stuff for BackgroundIO             * */
  81. /* *                             * */
  82. /* *************************************************** */
  83.  
  84. long  __stack         = 32768;
  85. char *__procname     = "SuperPlay";
  86. long  __priority     = 1;
  87. long  __BackGroundIO = 1;        /* TRUE : We DO BackGroundIO !     */
  88.  
  89. extern BPTR _Backstdout;        /* NULL, if started from Workbench */
  90.  
  91.  
  92. /* *************************************************** */
  93. /* *                             * */
  94. /* * MAIN                         * */
  95. /* *                             * */
  96. /* *************************************************** */
  97.  
  98. void main(long argc, char **argv)
  99. {
  100.  SetTaskPri(FindTask(N), __priority);
  101.  
  102.  if(argc && argv[1][0] =='?')
  103.   {
  104.    SP_Printf("%s%s%s", entry1_text, entry2_text, entry3_text);
  105.  
  106.    Leave(N, N, 0);
  107.   }
  108.  
  109.  if(OS_VER < 37) Leave("You need OS V2.04+ !", N, 20);
  110.  
  111.  IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37);
  112.  if(!IntuitionBase) Leave(intuitionlib_text, N, 20);
  113.  
  114.  GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37);
  115.  if(!GfxBase) Leave(graphicslib_text, N, 20);
  116.  
  117.  GadToolsBase = (struct Library *) OpenLibrary("gadtools.library", 37);
  118.  if(!GadToolsBase) Leave(gadtoolslib_text, N, 20);
  119.  
  120.  AslBase = (struct Library *) OpenLibrary("asl.library", 37);
  121.  if(!AslBase) Leave(asllib_text, N, 20);
  122.  
  123.  SuperPlayBase = (struct SuperPlayBase *) OpenLibrary("superplay.library", 3);
  124.  if(!SuperPlayBase) Leave(splib_text, N, 20);
  125.  
  126.  SPOList = SPS_GetSPOList();
  127.  SPS_HandleGadgets();
  128.  
  129.  Leave(N, N, 0);
  130. }
  131.  
  132. /* *************************************************** */
  133. /* *                             * */
  134. /* * Leave : Global Exit Function Replacement         * */
  135. /* *                             * */
  136. /* *************************************************** */
  137.  
  138. void __regargs Leave(char *errtext, APTR mlist, long code)
  139. {
  140.  if(Scr)
  141.   {
  142.    if(SP_Main_Wnd) CloseSP_Main_Window();
  143.  
  144.    CloseDownScreen();
  145.   }
  146.  
  147.  if(SPOList)    SPS_FreeSPOList(SPOList);
  148.  if(playhandle) SPL_FreeHandle(playhandle);
  149.  
  150.  if(SuperPlayBase)  CloseLibrary((APTR) SuperPlayBase);
  151.  if(AslBase)        CloseLibrary((APTR) AslBase);
  152.  if(GadToolsBase)   CloseLibrary((APTR) GadToolsBase);
  153.  if(GfxBase)        CloseLibrary((APTR) GfxBase);
  154.  if(IntuitionBase)  CloseLibrary((APTR) IntuitionBase);
  155.  
  156.  if(_Backstdout)
  157.   {
  158.    if(errtext) Write(_Backstdout, errtext, strlen(errtext));
  159.    Close(_Backstdout);
  160.   }
  161.  
  162.  exit(code); /* FAILED */
  163. }
  164.  
  165. /* *************************************************** */
  166. /* *                             * */
  167. /* * SPS_HandleGadgets : ...                         * */
  168. /* *                             * */
  169. /* *************************************************** */
  170.  
  171. void __regargs SPS_HandleGadgets(void)
  172. {
  173.  struct TagItem __aligned tags[3];
  174.  struct IntuiMessage *msg;
  175.  ULONG class, code, gadid, last_spogad = 0;
  176.  struct Gadget *address;
  177.  struct SPS_SPOEntry   *spe_node = N;
  178.  struct SPO_ObjectNode *spo_node = N;
  179.  ULONG retval = SPERR_NO_ERROR;
  180.  
  181.  spe_node = SPS_GetSPOEntry(SPOList, 0);
  182.  spo_node = spe_node->spe_SPO_ObjectNode;
  183.  
  184.  SetupScreen();
  185.  if(Scr)
  186.   {
  187.    OpenSP_Main_Window();
  188. /* SP_Main_Render(); */
  189.  
  190.    if(SP_Main_Wnd)
  191.     {
  192.      ModifyIDCMP(SP_Main_Wnd,   (BUTTONIDCMP|MXIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW)
  193.                               ^ (IDCMP_INTUITICKS | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS)
  194.                               |  IDCMP_VANILLAKEY | IDCMP_RAWKEY);
  195.  
  196.      tags[0].ti_Tag  = (Tag)   GTLV_Labels;
  197.      tags[0].ti_Data = (ULONG) SPOList;
  198.  
  199.      tags[1].ti_Tag  = (Tag)  TAG_DONE;
  200.      tags[1].ti_Data = (ULONG) N;
  201.  
  202.      GT_SetGadgetAttrsA(SP_Main_Gadgets[GD_SPOGad], SP_Main_Wnd, N, &tags[0]);
  203.  
  204.      for(;;)
  205.       {
  206.        if(retval)
  207.         {
  208.          if(retval == SPERR_ACTION_NOT_SUPPORTED) DisplayBeep(Scr);
  209.           else SPS_DisplayError(SPL_GetErrorString(retval));
  210.  
  211.          retval = SPERR_NO_ERROR;
  212.         }
  213.  
  214.        WaitPort(SP_Main_Wnd->UserPort);
  215.  
  216.        msg = GT_GetIMsg(SP_Main_Wnd->UserPort);
  217.        if(!msg) continue;
  218.  
  219.        class   = msg->Class;
  220.        code    = msg->Code;
  221.        address = msg->IAddress;
  222.        gadid   = address->GadgetID;
  223.  
  224.        GT_ReplyIMsg(msg);
  225.  
  226.        if(class == IDCMP_CLOSEWINDOW) break;
  227.        if(class == IDCMP_VANILLAKEY)
  228.         {
  229.          switch(toupper(code))
  230.           {
  231.            case 'O' : {
  232.                        if(last_spogad < SPOList->spl_NumEntries-1) last_spogad++;
  233.                         else                                       last_spogad = 0;
  234.  
  235.                        tags[0].ti_Tag  = (Tag)   GTLV_Top;
  236.                        tags[0].ti_Data = (ULONG) last_spogad;
  237.  
  238.                        tags[1].ti_Tag  = (Tag)  GTLV_Selected;
  239.                        tags[1].ti_Data = (ULONG) last_spogad;
  240.  
  241.                        tags[2].ti_Tag  = (Tag)  TAG_DONE;
  242.                        tags[2].ti_Data = (ULONG) N;
  243.  
  244.                        GT_SetGadgetAttrsA(SP_Main_Gadgets[GD_SPOGad], SP_Main_Wnd, N, &tags[0]);
  245.  
  246.                        break;
  247.                       }
  248.            case 'C' : { class = IDCMP_GADGETUP; gadid = GD_ConvertGad; break; }
  249.            case 'P' : { class = IDCMP_GADGETUP; gadid = GD_PlayGad;    break; }
  250.            case 'S' : { class = IDCMP_GADGETUP; gadid = GD_StopGad;    break; }
  251.            case 'T' : { class = IDCMP_GADGETUP; gadid = GD_ContGad;    break; }
  252.            case 'F' : { class = IDCMP_GADGETUP; gadid = GD_ForGad;     break; }
  253.            case 'B' : { class = IDCMP_GADGETUP; gadid = GD_BackGad;    break; }
  254.            case 'I' : { class = IDCMP_GADGETUP; gadid = GD_InfoGad;    break; }
  255.            case 'L' : { class = IDCMP_GADGETUP; gadid = GD_LEDGad;     break; }
  256.            default : break;
  257.           }
  258.         }
  259.        if(   class == IDCMP_GADGETUP
  260.           || class == IDCMP_GADGETDOWN)
  261.         {
  262.          switch(gadid)
  263.           {
  264.            case GD_SPOGad :
  265.             {
  266.              spe_node = SPS_GetSPOEntry(SPOList, code);
  267.              spo_node = spe_node->spe_SPO_ObjectNode;
  268.  
  269.              last_spogad = code;
  270.  
  271.              break;
  272.             }
  273.            case GD_ConvertGad :
  274.             {
  275.              retval = SPS_ConvRequest(spe_node->spe_ObjectSubCode);
  276.  
  277.              break;
  278.             }
  279.            case GD_PlayGad :
  280.             {
  281.              retval = SPS_PlayRequest(TRUE);
  282.  
  283.              break;
  284.             }
  285.            case GD_StopGad :
  286.             {
  287.              if(playhandle) SPL_StopReplay(playhandle);
  288.               else SPS_DisplayError("No File loaded");
  289.  
  290.              break;
  291.             }
  292.            case GD_ContGad :
  293.             {
  294.              if(playhandle) retval = SPL_ContinueReplay(playhandle);
  295.               else SPS_DisplayError("No File loaded");
  296.  
  297.              break;
  298.             }
  299.            case GD_ForGad :
  300.             {
  301.              if(playhandle) retval = SPL_FastForward(playhandle);
  302.               else SPS_DisplayError("No File loaded");
  303.  
  304.              break;
  305.             }
  306.            case GD_BackGad :
  307.             {
  308.              if(playhandle) retval = SPL_FastBackward(playhandle);
  309.               else SPS_DisplayError("No File loaded");
  310.  
  311.              break;
  312.             }
  313.            case GD_InfoGad :
  314.             {
  315.              if(playhandle) retval = SPL_FileInfoRequest(playhandle, SP_Main_Wnd, N);
  316.               else SPS_DisplayError("No File loaded");
  317.  
  318.              break;
  319.             }
  320.            case GD_LEDGad :
  321.             {
  322.              UBYTE *address = (UBYTE *) 0xbfe001;
  323.  
  324.              if(*address & 2) /* it's OFF, turn it ON */ *address &= 253;
  325.               else            /* else turn it OFF     */ *address |= 2;
  326.  
  327.              break;
  328.             }
  329.            default : break;
  330.           }
  331.         }
  332.       }
  333.  
  334.      while( msg = GT_GetIMsg(SP_Main_Wnd->UserPort) ) GT_ReplyIMsg(msg);
  335.     }else Leave(no_win_text, N, 202);
  336.   }else Leave(no_scr_text, N, 202);
  337. }
  338.  
  339. /* *************************************************** */
  340. /* *                             * */
  341. /* * SPS_Play : Play Routine                         * */
  342. /* *                             * */
  343. /* *************************************************** */
  344.  
  345. ULONG __regargs SPS_Play(char *filename, ULONG flag)
  346. {
  347.  ULONG retval = SPERR_NO_ERROR;
  348.  
  349.  if(playhandle)
  350.   {
  351.    SPL_FreeHandle(playhandle); playhandle = N;
  352.   }
  353.  
  354.  playhandle = SPL_AllocHandle(N);
  355.  if(playhandle)
  356.   {
  357.    if(!(retval = SPL_InitHandleAsDOS(playhandle, N)))
  358.     {
  359.      if(flag) retval = SPL_SuperPlay(playhandle, filename);
  360.       else    retval = SPL_ReadPlayData(playhandle, filename);
  361.  
  362.     }else retval = SPERR_NO_HANDLE;
  363.   }
  364.  
  365.  return(retval);
  366. }
  367.  
  368. /* *************************************************** */
  369. /* *                             * */
  370. /* * SPS_PlayRequest : FileRequest, then SPS_Play()  * */
  371. /* *                             * */
  372. /* *************************************************** */
  373.  
  374. struct SP_RememberPath __aligned sprp_show;
  375.  
  376. ULONG __regargs SPS_PlayRequest(ULONG flag)
  377. {
  378.  char *filename = sprp_show.rp_Path;
  379.  ULONG retval = SPERR_NO_ERROR;
  380.  long bool;
  381.  
  382.  if(flag) bool = SPS_FileRequest(&sprp_show, "Select File to Play :", "Play", "Quit");
  383.   else    bool = SPS_FileRequest(&sprp_show, "Select File to Convert :", "Convert", "Quit");
  384.  
  385.  if(filename[0]==(char) 0) bool = FALSE;
  386.  
  387.  if(bool) retval = SPS_Play(filename, flag);
  388.  
  389.  return(retval);
  390. }
  391.  
  392. /* *************************************************** */
  393. /* *                             * */
  394. /* * SPS_Conv : Conv Routine                         * */
  395. /* *                             * */
  396. /* *************************************************** */
  397.  
  398. ULONG __regargs SPS_Conv(char *filename, ULONG code)
  399. {
  400.  ULONG retval = SPERR_NO_ERROR;
  401.  APTR savehandle = N;
  402.  
  403.  savehandle = SPL_AllocHandle(N);
  404.  if(savehandle)
  405.   {
  406.                retval = SPL_SetWriteType(savehandle, code, N);
  407.    if(!retval) retval = SPL_SetWriteName(savehandle, filename, N);
  408.    if(!retval) retval = SPL_SuperWrite(savehandle, playhandle);
  409.  
  410.    SPL_FreeHandle(savehandle);
  411.   }
  412.  
  413.  return(retval);
  414. }
  415.  
  416. /* *************************************************** */
  417. /* *                             * */
  418. /* * SPS_ConvRequest : FileRequest, then SPS_Conv()  * */
  419. /* *                             * */
  420. /* *************************************************** */
  421.  
  422. struct SP_RememberPath __aligned sprp_save;
  423.  
  424. ULONG __regargs SPS_ConvRequest(ULONG code)
  425. {
  426.  char *filename = sprp_save.rp_Path;
  427.  ULONG retval = SPERR_NO_ERROR;
  428.  long bool;
  429.  
  430.  retval = SPS_PlayRequest(FALSE);
  431.  if(!retval)
  432.   {
  433.    bool = SPS_FileRequest(&sprp_save, "Enter new FileName :", "Done", "Quit");
  434.  
  435.    if(filename[0]==(char) 0) bool = FALSE;
  436.  
  437.    if(bool) retval = SPS_Conv(filename, code);
  438.   }
  439.  
  440.  return(retval);
  441. }
  442.  
  443. /* *************************************************** */
  444. /* *                             * */
  445. /* * SPS_FileRequest : FileRequester Routine         * */
  446. /* *                             * */
  447. /* *************************************************** */
  448.  
  449. ULONG __regargs SPS_FileRequest(struct SP_RememberPath *sprp, char *title, char *left, char *right)
  450. {
  451.  struct TagItem __aligned tags[7];
  452.  struct FileRequester *request = N;
  453.  ULONG bool = FALSE;
  454.  
  455.  tags[0].ti_Tag  = (Tag)   ASLFR_TitleText;
  456.  tags[0].ti_Data = (ULONG) title;
  457.  
  458.  tags[1].ti_Tag  = (Tag)   ASLFR_PositiveText;
  459.  tags[1].ti_Data = (ULONG) left;
  460.  
  461.  tags[2].ti_Tag  = (Tag)   ASLFR_NegativeText;
  462.  tags[2].ti_Data = (ULONG) right;
  463.  
  464.  tags[3].ti_Tag  = (Tag)   ASLFR_InitialFile;
  465.  tags[3].ti_Data = (ULONG) sprp->rp_File;
  466.  
  467.  tags[4].ti_Tag  = (Tag)   ASLFR_InitialDrawer;
  468.  tags[4].ti_Data = (ULONG) sprp->rp_Dir;
  469.  
  470.  tags[5].ti_Tag  = (Tag)   ASLFR_RejectIcons;
  471.  tags[5].ti_Data = (ULONG) TRUE;
  472.  
  473.  tags[6].ti_Tag  = (Tag)   TAG_DONE;
  474.  tags[6].ti_Data = (ULONG) N;
  475.  
  476.  request = AllocAslRequest(ASL_FileRequest, N);
  477.  if(request)
  478.   {
  479.    if(AslRequest(request, &tags[0]))
  480.     {
  481.      strcpy(sprp->rp_Dir,  request->rf_Dir);
  482.      strcpy(sprp->rp_File, request->rf_File);
  483.  
  484.      strcpy(sprp->rp_Path, request->rf_Dir);
  485.  
  486.      if(   (sprp->rp_Path[strlen(sprp->rp_Path)-1] != ':')
  487.          &&(sprp->rp_Path[strlen(sprp->rp_Path)-1] != '/')
  488.          &&(sprp->rp_Path[strlen(sprp->rp_Path)-1] != ' ')
  489.          &&(sprp->rp_Path[0] != (char) 0                 ) ) strcat(sprp->rp_Path, "/");
  490.  
  491.      strcat(sprp->rp_Path, request->rf_File);
  492.  
  493.      bool = TRUE;
  494.     }
  495.  
  496.    FreeFileRequest(request);
  497.   }
  498.  
  499.  return(bool);
  500. }
  501.  
  502. void __regargs SPS_DisplayError(char *text)
  503. {
  504.  struct Window *popup_win = N;
  505.  ULONG idcmp = N;
  506.  struct EasyStruct *estr = AllocVec(sizeof(struct EasyStruct), (MEMF_CLEAR|MEMF_PUBLIC));
  507.  
  508.  if(estr)
  509.   {
  510.    estr->es_StructSize   = sizeof(struct EasyStruct);
  511.    estr->es_Flags        = N;
  512.    estr->es_Title        = "SuperPlay Message";
  513.    estr->es_TextFormat   = text;
  514.    estr->es_GadgetFormat = "Confirm";
  515.  
  516.                   popup_win = SP_Main_Wnd;
  517.    if(!popup_win) popup_win = IntuitionBase->FirstScreen->FirstWindow;
  518.  
  519.    EasyRequestArgs(popup_win, estr, &idcmp, N);
  520.    FreeVec(estr);
  521.   }
  522. }
  523.  
  524. /* *************************************************** */
  525. /* *                                                 * */
  526. /* * SP_Printf : Replacement for printf()-Output     * */
  527. /* *                                                 * */
  528. /* *************************************************** */
  529.  
  530. #define KIP_BUFLEN (1200)
  531.  
  532. extern void Fmt(void);
  533.  
  534. extern BPTR _Backstdout;
  535.  
  536. void __stdargs SP_Printf(char *formatstring, ...)
  537. {
  538.  UBYTE *buffer;
  539.  
  540.  if(_Backstdout)
  541.   {
  542.    buffer = (BYTE *) AllocMem(KIP_BUFLEN, MEMF_CLEAR);
  543.    if(buffer)
  544.     {
  545.      RawDoFmt((APTR) formatstring, (APTR) (((ULONG *)&formatstring)+1), (APTR) &Fmt, (APTR) buffer);
  546.  
  547.      Write(_Backstdout, buffer, strlen(buffer));
  548.  
  549.      FreeMem(buffer, KIP_BUFLEN);
  550.     }
  551.   }
  552. }
  553.  
  554. /* *************************************************** */
  555. /* *                                                 * */
  556. /* * SP_SPrintf : Replacement for sprintf()-Routine  * */
  557. /* *                                                 * */
  558. /* *************************************************** */
  559.  
  560. /* currently unused */
  561.  
  562. #ifdef USE_SP_SPRINTF
  563.  
  564. void __stdargs SP_SPrintf(char *buffer, char *formatstring, ...)
  565. {
  566.  RawDoFmt((APTR) formatstring, (APTR) (((ULONG *)&formatstring)+1), (APTR) &Fmt, (APTR) buffer);
  567. }
  568.  
  569. #endif /* USE_SP_SPRINTF */
  570.